{include file="header" /}
<div class="fly-msg" style="margin-bottom: 20px;">积分购买/兑换 </div>
<div class="layui-row layui-col-space20">
    <div class="layui-col-md12">
        <div class="fly-home fly-panel" style="text-align: left">
            <form class="layui-form" action="{:url('OnlineRecharge/exchange')}" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">余额：</label>
                    <div class="layui-form-mid layui-word-aux"><span style="font-weight:bold;color: red">	{$userinfo.amount}</span>元,<span  style="font-weight:bold;color: red"> {$userinfo.point}</span> 点</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">支出：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="money" id="money" required lay-verify="required|number" lay-reqText="请输入要兑换的金额" placeholder="兑换的金额" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">元	可兑换积分数：<span  style="font-weight:bold;color: red" id="point">0</span>点</div>
                    <div class="layui-form-mid layui-word-aux"><span  style="font-weight:bold;color: red" id="msg_desc">&nbsp;</span></div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">验证码：</label>
                    <div class="layui-input-inline">

                        <input type="text" name="code"  id="code" lay-verify="required" lay-reqText="请输入验证码" placeholder="验证码" autocomplete="off" class="layui-input" maxlength="4">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <img id="verify" src="{:url('api/checkcode/getVerify','font_size=18&imageW=130&imageH=38')}" alt="验证码" class="captcha" style="height: 44px">
                    </div>
                    <div class="layui-form-mid layui-word-aux">请输入验证码</div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="hidden" name="act" value="exchange">
                        <input class="layui-btn layui-btn-disabled" type="button" lay-submit lay-filter="formDemo" id="exchange" value="兑换">

                    </div>
                </div>
            </form>
        </div>
    </div>

</div>
{include file="footer" /}


<script>
    //Demo
    layui.use(['form', 'layer', 'jquery'], function(){
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        //监听提交
        form.on('submit(formDemo)', function(data){

            $.post('{:url("OnlineRecharge/exchange")}',data.field,function(res){
                $('#point').html(res.data.points);

                if(res.code!=0){
                    layer.msg(res.data.msg_title,{icon:1},function(){
                        $("#verify").click();
                        $("#code").val('');
                        window.location.href='{:url("OnlineRecharge/expenses_record")}';
                    })
                }else{
                    layer.msg(res.data.msg_title,{icon:2},function(){
                        $("#verify").click();
                        $("#code").val('');
                    })
                }


            },'json');
            console.log(data.field);
            return false;
            //layer.msg(JSON.stringify(data.field));
          //  return false;
        });

        var exchange_elm= $('#exchange');
        $(function(){
            exchange_elm.removeAttr('lay-submit');
            exchange_elm.removeAttr('lay-filter');
        });
        $('#money').keyup(function () {
            exchange_elm.addClass('layui-btn-disabled');
            exchange_elm.removeAttr('lay-submit');
            exchange_elm.removeAttr('lay-filter');
            var money=$(this).val();
            //chek_exchange_money
            $.post('{:url("OnlineRecharge/exchange")}',{money:money,act:'chek_exchange_money'},function(res){
                $('#point').html(res.data.points);
                $('#msg_desc').html(res.data.msg_title);
                if(res.code!=0){
                    exchange_elm.attr('lay-submit','lay-submit');
                    exchange_elm.attr('lay-filter','formDemo');
                    exchange_elm.removeClass('layui-btn-disabled');
                }else{

                }


            },'json');

        });

            //刷新验证码
            $("#verify").click(function() {
                var verifyimg = $("#verify").attr("src");
                $("#verify").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
            });

    });

</script>